2020-2021 Sunseeker Telemetry and Lighting System
sd24_b_ex2_singleConvChannelGroup.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 #include "driverlib.h"
33 
34 //*****************************************************************************
35 // MSP430F673x Demo - SD24_B, Single Conversion on a Group of 3 Channels
36 //
37 // Description: This program uses the SD24_B module to perform a single
38 // conversion on a group of 3 channels (0, 1 and 2). An SD24_B interrupt
39 // occurs when the conversions have completed. Test by applying voltages
40 // to the 3 input channels and setting a breakpoint at the line indicated
41 // below. Run program until it reaches the breakpoint, then use the
42 // debugger's watch window to view the conversion results. Results (upper 16
43 // bits only) for all 3 channels are stored in the array "results".
44 // ACLK = n/a, MCLK = SMCLK = DCO = ~ 1.1MHz
45 // //* For minimum Vcc required for SD24_B module - see datasheet *//
46 // //* 100nF cap between Vref and AVss is recommended when using 1.5V REF *//
47 //
48 // MSP430F673x
49 // -----------------
50 // /|\| XIN|-
51 // | | |
52 // --|RST XOUT|-
53 // | |
54 // Vin1+ -->|SD0P0 |
55 // Vin1- -->|SD0N0 |
56 // Vin2+ -->|SD1P0 |
57 // Vin2- -->|SD1N0 |
58 // Vin3+ -->|SD2P0 |
59 // Vin3- -->|SD2N0 |
60 // | VREF |---+
61 // | | |
62 // | | -+- 100nF
63 // | | -+-
64 // | | |
65 // | AVss |---+
66 // | |
67 //
68 // M. Swanson
69 // Texas Instruments, Inc
70 // December 2011
71 // Built with CCS Version: 5.1.0 and IAR Embedded Workbench Version: 5.40.1
72 //*****************************************************************************
73 
74 /* Array to store SD24_B conversion results */
75 uint32_t results[3];
76 
77 void main(void)
78 {
79  WDT_A_hold(WDT_A_BASE); // Stop WDT
80 
81  // Select internal REF
82  // Select SMCLK as SD24_B clock source
83 
84  SD24_B_initParam initParam = {0};
85  initParam.clockSourceSelect = SD24_B_CLOCKSOURCE_SMCLK;
86  initParam.clockPreDivider = SD24_B_PRECLOCKDIVIDER_1;
87  initParam.clockDivider = SD24_B_CLOCKDIVIDER_1;
88  initParam.referenceSelect = SD24_B_REF_INTERNAL;
89  SD24_B_init(SD24_BASE, &initParam);
90 
91  SD24_B_initConverterParam initConverterParam0 = {0};
92  initConverterParam0.converter = SD24_B_CONVERTER_0;
93  initConverterParam0.alignment = SD24_B_ALIGN_RIGHT;
94  initConverterParam0.startSelect = SD24_B_CONVERSION_SELECT_GROUP1;
95  initConverterParam0.conversionMode = SD24_B_CONTINUOUS_MODE;
96  SD24_B_initConverter(SD24_BASE, &initConverterParam0);
97 
98  SD24_B_initConverterParam initConverterParam1 = {0};
99  initConverterParam1.converter = SD24_B_CONVERTER_1;
100  initConverterParam1.alignment = SD24_B_ALIGN_RIGHT;
101  initConverterParam1.startSelect = SD24_B_CONVERSION_SELECT_GROUP1;
102  initConverterParam1.conversionMode = SD24_B_CONTINUOUS_MODE;
103  SD24_B_initConverter(SD24_BASE, &initConverterParam1);
104 
105  SD24_B_initConverterParam initConverterParam2 = {0};
106  initConverterParam2.converter = SD24_B_CONVERTER_2;
107  initConverterParam2.alignment = SD24_B_ALIGN_RIGHT;
108  initConverterParam2.startSelect = SD24_B_CONVERSION_SELECT_GROUP1;
109  initConverterParam2.conversionMode = SD24_B_CONTINUOUS_MODE;
110  SD24_B_initConverter(SD24_BASE, &initConverterParam2);
111 
112  SD24_B_clearInterrupt(SD24_BASE,
113  SD24_B_CONVERTER_2,
114  SD24_B_CONVERTER_INTERRUPT ); // Clear channel 2 interrupt
115  SD24_B_enableInterrupt(SD24_BASE,
116  SD24_B_CONVERTER_2,
117  SD24_B_CONVERTER_INTERRUPT ); // Enable channel 2 interrupt
118 
119  __delay_cycles(0x3600); // Delay for 1.5V REF startup
120 
121  while (1)
122  {
123 
124  SD24_B_startGroupConversion(SD24_BASE,
125  SD24_B_CONVERTER_1); // Set bit to start conversion
126 
127  __bis_SR_register(LPM0_bits | GIE); // Enter LPM0 w/ interrupts
128 
129  SD24_B_stopGroupConversion(SD24_BASE,
130  SD24_B_CONVERTER_1); // Clear bit for next conversion
131 
132  __no_operation(); // SET BREAKPOINT HERE
133  }
134 }
135 
136 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
137 #pragma vector=SD24B_VECTOR
138 __interrupt
139 #elif defined(__GNUC__)
140 __attribute__((interrupt(SD24B_VECTOR)))
141 #endif
142 void SD24BISR(void)
143 {
144  switch (SD24BIV)
145  {
146  case SD24BIV_SD24OVIFG: // SD24MEM Overflow
147  break;
148  case SD24BIV_SD24TRGIFG: // SD24 Trigger IFG
149  break;
150  case SD24BIV_SD24IFG0: // SD24MEM0 IFG
151  break;
152  case SD24BIV_SD24IFG1: // SD24MEM1 IFG
153  break;
154  case SD24BIV_SD24IFG2: // SD24MEM2 IFG
155  results[0] = SD24_B_getResults(SD24_BASE,
156  SD24_B_CONVERTER_0); // Save CH0 results (clears IFG)
157  results[1] = SD24_B_getResults(SD24_BASE,
158  SD24_B_CONVERTER_1); // Save CH1 results (clears IFG)
159  results[2] = SD24_B_getResults(SD24_BASE,
160  SD24_B_CONVERTER_2); // Save CH2 results (clears IFG)
161  break;
162  }
163 
164  __bic_SR_register_on_exit(LPM0_bits); // Exit LPM0
165 }
166 
__no_operation()
__bic_SR_register_on_exit(LPM3_bits|GIE)
__delay_cycles(500000)
uint32_t results[3]